package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecycleChildItemClickListener;
import com.lemon.smartsafetynew.entity.record.MajorHazardVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by JiangAn on 2018/5/28.
 */

public class MajorHazardNewAdapter extends LemonRcvAdapter<MajorHazardVo> {
    private RecycleChildItemClickListener<MajorHazardVo> mListener;
    public MajorHazardNewAdapter(@Nullable List<MajorHazardVo> data, RecycleChildItemClickListener<MajorHazardVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new MajorHazardNewAdapter.MajorHazardItem();
    }

    public class MajorHazardItem implements AdapterItem<MajorHazardVo> {
        @Bind(R.id.tv_space_name)
        TextView tvSpaceName;
        @Bind(R.id.record_info_iv)
        ImageView recordInfoIv;
        @Bind(R.id.tv_position_detail)
        TextView tvPositionDetail;
        @Bind(R.id.tv_operate_type)
        TextView tvOperateType;
        @Bind(R.id.tv_store_position_power)
        TextView tvStorePositionPower;
        @Bind(R.id.tv_outspace_people_count)
        TextView tvOutspacePeopleCount;
        @Bind(R.id.tv_reform_person)
        TextView tvReformPerson;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        @Bind(R.id.tv_contact_number)
        TextView tvContactNumber;
        private MajorHazardVo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_new_major_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });

            tvContactNumber.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onChildItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(MajorHazardVo majorHazardVo, int position) {
            data = majorHazardVo;
            pos = position;
            tvSpaceName.setText(CommonUtil.avoidNullString(majorHazardVo.getMajor_danger_name()));
            if (majorHazardVo.getDanger_level() != null) {
                Integer status = majorHazardVo.getDanger_level();
                switch (status) {
                    case 0:
                        recordInfoIv.setVisibility(View.GONE);
                        break;
                    case 1:
                        recordInfoIv.setVisibility(View.VISIBLE);
                        recordInfoIv.setImageResource(R.mipmap.record_level_4);
                        break;
                    case 2:
                        recordInfoIv.setVisibility(View.VISIBLE);
                        recordInfoIv.setImageResource(R.mipmap.record_level_3);
                        break;
                    case 3:
                        recordInfoIv.setVisibility(View.VISIBLE);
                        recordInfoIv.setImageResource(R.mipmap.record_level_2);
                        break;
                    case 4:
                        recordInfoIv.setVisibility(View.VISIBLE);
                        recordInfoIv.setImageResource(R.mipmap.record_level_1);
                        break;
                }
            }
            tvSpaceName.setText(CommonUtil.avoidNullString(majorHazardVo.getMajor_danger_name()));
            tvPositionDetail.setText(CommonUtil.avoidNullString(majorHazardVo.getAddress()));
            tvOperateType.setText(CommonUtil.avoidNullString(majorHazardVo.getOperations()));
            tvStorePositionPower.setText(CommonUtil.avoidNullString(majorHazardVo.getStorage_place_property()));
            tvOutspacePeopleCount.setText(CommonUtil.avoidNullString(majorHazardVo.getExpose_people_num()));
            tvReformPerson.setText(CommonUtil.avoidNullString(majorHazardVo.getCharger()));
            if(!TextUtils.isEmpty(majorHazardVo.getCharger_mobile())) {
                tvContactNumber.setVisibility(View.VISIBLE);
                tvContactNumber.setText(CommonUtil.avoidNullString(majorHazardVo.getCharger_mobile()));
            }else{
                tvContactNumber.setVisibility(View.GONE);
            }
        }
    }
}
